package str

func partition(s string) [][]string {

	judge := func(bytelist []byte) bool {

		left, right := 0, len(s)-1
		for left < right {
			if bytelist[left] != bytelist[right] {
				return false
			}
			left++
			right--
		}
		return true
	}

	res := [][]string{}

	var backtrack func(bytelist []byte, track []string)
	backtrack = func(bytelist []byte, track []string) {
		if len(bytelist) == 0 {
			temp := make([]string, len(track))
			copy(temp, track)
			res = append(res, temp)

		}

		for i := 1; i <= len(bytelist); i++ {
			if judge(bytelist[:i]) {
				track = append(track, string(bytelist[:i]))
				backtrack(bytelist[i:], track)
				track = track[:len(track)-1]
			}
		}
	}

	return res

}
